package com.mf.service.impl.basic.webPage;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mf.exception.GraceException;
import com.mf.service.basic.webPage.ServicePageItem;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.mf.entity.dto.basic.webPage.DtoPage;
import com.mf.entity.req.basic.search.webPage.SearchReqPage;
import com.mf.mapper.basic.webPage.MapperPage;
import com.mf.service.basic.webPage.ServicePage;


@Service
public class ImplServicePage extends ServiceImpl<MapperPage, DtoPage> implements ServicePage {
    @Resource
    private ServicePageItem servicepageItem;

    /**
     * 参数查询条件
     */
    @Override
    public LambdaQueryWrapper<DtoPage> fillParams(SearchReqPage params) {
        LambdaQueryWrapper<DtoPage> w = loadQw();
        w.like(StringUtils.isNotBlank(params.getKey()), DtoPage::getPname, params.getKey());
        w.orderByDesc(DtoPage::getId);
        return w;
    }

    /**
     * 删除
     */
    @Override
    public void deleteById(Integer id) {
        GraceException.display(servicepageItem.countByPageId(id) > 0, "当前页面有绑定明细不可删除");
        removeById(id);
    }
}